package com.iflytek.universitymanagement.controller;

import com.iflytek.universitymanagement.domain.TutoringPlan;
import com.iflytek.universitymanagement.domain.TutoringPlanWithStudentName;
import com.iflytek.universitymanagement.service.TutoringPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tutoring-plans")
public class TutoringPlanController {

    @Autowired
    private TutoringPlanService tutoringPlanService;

    // 获取所有辅导计划（带学生姓名）
    @GetMapping
    public List<TutoringPlanWithStudentName> getAllTutoringPlans() {
        return tutoringPlanService.getAllTutoringPlans();
    }

    // 获取指定ID的辅导计划
    @GetMapping("/{planId}")
    public TutoringPlan getTutoringPlan(@PathVariable Integer planId) {
        return tutoringPlanService.getTutoringPlanById(planId);
    }

    // 创建辅导计划
    @PostMapping
    public String createTutoringPlan(@RequestBody TutoringPlan tutoringPlan) {
        // 可以在这里做一些验证，确保传入的学生ID有效
        boolean isSaved = tutoringPlanService.createTutoringPlan(tutoringPlan);
        return isSaved ? "辅导计划创建成功" : "创建辅导计划失败";
    }
    // 更新辅导计划
    @PutMapping("/{planId}")
    public String updateTutoringPlan(@PathVariable Integer planId, @RequestBody TutoringPlan tutoringPlan) {
        boolean isUpdated = tutoringPlanService.updateTutoringPlan(planId, tutoringPlan);
        return isUpdated ? "辅导计划更新成功" : "更新辅导计划失败";
    }

    // 删除辅导计划
    @DeleteMapping("/{planId}")
    public String deleteTutoringPlan(@PathVariable Integer planId) {
        boolean isDeleted = tutoringPlanService.deleteTutoringPlan(planId);
        return isDeleted ? "辅导计划删除成功" : "删除辅导计划失败";
    }
}
